package Test;

public class test1 {
    //移动零
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6,7,8,9};
        int target = 7;
        int left = 0;
        int right = 0;
        int sum = 0;
        int len = arr.length+1;

        while (right < arr.length){

            sum += arr[right];

            while (sum >= target){
                len = Math.min(len,right-left+1);
                sum -= arr[left];
                left++;
            }
            right++;
        }
        if(len == arr.length+1){
            System.out.println(0);
        }else{
            System.out.println(len);

        }
    }
}
